package cn.kgc.microservicecloudconsumercategoryfeign80.controller;

import cn.kgc.microservicecloudapi.pojo.Category;
import cn.kgc.microservicecloudapi.pojo.ResultEntity;
import cn.kgc.microservicecloudconsumercategoryfeign80.service.CategoryClientService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/consumer/category")
public class CategoryController {
//    private static final String REST_URL_PREFIX="http://microservicecloud-provider-dept-8001/provider/category";

    //private static final String REST_URL_PREFIX="http://MICROSERVICECLOUD-PROVIDER-CATEGORY/provider/category";

    /*@Resource
    RestTemplate restTemplate;*/

    @Resource
    CategoryClientService categoryClientService;

    @RequestMapping("/list")
    public ResultEntity<List<Category>> list(){
        return categoryClientService.list();
        //return restTemplate.getForObject(REST_URL_PREFIX+"/list", ResultEntity.class);
    }

    @RequestMapping("/get/{id}")
    public ResultEntity<Category> get(@PathVariable Integer id){
        return categoryClientService.get(id);
        //return restTemplate.getForObject(REST_URL_PREFIX+"/get/"+id,ResultEntity.class);
    }

    @RequestMapping("/update")
    public ResultEntity<String> update(@RequestBody Category category){
        return categoryClientService.update(category);
        //return restTemplate.postForObject(REST_URL_PREFIX+"/update",category,ResultEntity.class);
    }

    @RequestMapping("/insert")
    public ResultEntity<String> insert(@RequestBody Category category){
        return categoryClientService.insert(category);
        //return restTemplate.postForObject(REST_URL_PREFIX+"/insert",category,ResultEntity.class);
    }

    @RequestMapping("/delete/{id}")
    public ResultEntity<String> delete(@PathVariable Integer id){
        return categoryClientService.delete(id);
        //return restTemplate.getForObject(REST_URL_PREFIX+"/delete/"+id,ResultEntity.class);
    }
}
